package online_exams.controller;

import online_exams.domain.TExamRecordEntity;
import online_exams.service.TExamRecordService;
import online_exams.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 考试记录表(TExamRecord)表控制层
 *
 * @author makejava
 * @since 2024-12-19 16:50:03
 */
@RestController
@RequestMapping("tExamRecord")
public class TExamRecordController {
    /**
     * 服务对象
     */
    @Autowired
    private TExamRecordService tExamRecordService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public Result selectOne(@PathVariable Serializable id) {
        return Result.success(tExamRecordService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param TExamRecordEntity 实体对象
     * @return 新增结果
     */
    @PostMapping
    public Result insert(@RequestBody TExamRecordEntity tExamRecordEntity) {
        return Result.success(tExamRecordService.save(tExamRecordEntity));
    }

    /**
     * 修改数据
     *
     * @param TExamRecordEntity 实体对象
     * @return 修改结果
     */
    @PutMapping
    public Result update(@RequestBody TExamRecordEntity tExamRecordEntity) {
        return Result.success(tExamRecordService.updateById(tExamRecordEntity));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public Result delete(@RequestParam("idList") List<Long> idList) {
        return Result.success(tExamRecordService.removeByIds(idList));
    }
}

